#include <lpc23xx.h>
#include "LCD.h"
void init_serial (void);
unsigned char putchar (unsigned char ch) ;
unsigned char getchar (void) ;

unsigned int flasher = 0x0000000; 	
int main (void)
{
    
unsigned int delay; //
	/* Reset all GPIO pins to default: primary function */


	lcd_init();					   //
	lcd_clear();				  //
	set_cursor(2,0);			   // Agaf=/
    lcd_print("UART Example");	 //

    PINSEL0 = 0x00000000;
    PINSEL1 = 0x00000000;
    PINSEL2 = 0x00000000;
    PINSEL3 = 0x00000000;
    PINSEL4 = 0x00000000;
    PINSEL5 = 0x00000000;
    PINSEL6 = 0x00000000;
    PINSEL7 = 0x00000000;
    PINSEL8 = 0x00000000;
    PINSEL9 = 0x00000000;
    PINSEL10 = 0x00000000;
    
    IODIR0 = 0x00000000;
    IODIR1 = 0x00000000;
	  IOSET0 = 0x00000000;
    IOSET1 = 0x00000000;
    
    FIO0DIR = 0x00000000;
    FIO1DIR = 0x00000000;
    FIO2DIR = 0x00000000;
    FIO3DIR = 0x00000000;
    FIO4DIR = 0x00000000;
    
    FIO0SET = 0x00000000;
    FIO1SET = 0x00000000;
    FIO2SET = 0x00000000;
    FIO3SET = 0x00000000;
    FIO4SET = 0x00000000;					

    FIO2DIR = 0x000000FF;
    FIO2MASK = 0xFFFFFF00; 
    
    init_serial();
    
    while(1)
    {
    
        putchar(getchar());
      }
    
    
return (0);    
}

void init_serial (void)			  /* Initialize Serial Interface       */
{               	   
    PINSEL0 |= 0x40000000;       /* Enable TxD1                       */
    PINSEL1 |= 0x00000001;       /* Enable RxD1                       */
  
    PCLKSEL0  = 0x02 << 8;         //set UART clock to 30Mkz
  
    U1LCR 	= 0x00000083;         /* 8 bits, no Parity, 1 Stop bit     */
    U1DLL 	= 0x000000C3;         /* 9600 Baud Rate @ 30MHz VPB Clock  */
    U1DLM   = 0x00000000;
    U1LCR 	= 0x00000003;        /* DLAB = 0                          */
}


unsigned char putchar (unsigned char ch) 			  /* Write character to Serial Port    */
{                  		

  
  while (!(U1LSR & 0x20));
  return (U1THR = ch);
}


unsigned char getchar (void) 				/* Read character from Serial Port   */
{                    

  while (!(U1LSR & 0x01));

  return (U1RBR);
}